**************************************************************************************************************************************************
****************************** Wealth-Income Ratios in Free Market Capitalism: Switzerland, 1900-2020 ********************************************
**************************************************************************************************************************************************
clear all
set more off
set scheme s1color  
cap set scheme mygraphs

**Author: Enea Baselgia and Isabel Z. Martinez
**Date: January, 25 2023

*** set this path to the current directory
*** global mypath "C:\Users\EBaselgia\Dropbox\WIR_project\Publication_process\replication"


* ESTIMATES OF AGRICULTURAL LAND - CAPITALIZATION METHOD *

***read data 
cd "$mypath/final_data/"
use "WIR_final.dta", clear

keep year ch_nni_T ch_pW_T ch_pWIR ///
AU_domW_agriW_T_R DE_domW_agriW_T_R FR_domW_agriW_T_R ES_domW_agriW_T_R IT_domW_agriW_T_R GB_domW_agriW_T_R SE_domW_agriW_T_R US_domW_agriW_T_R JP_domW_agriW_T_R NO_domW_agriW_T_R CA_domW_agriW_T_R ///
AU_pW_T_R DE_pW_T_R FR_pW_T_R ES_pW_T_R IT_pW_T_R GB_pW_T_R SE_pW_T_R US_pW_T_R JP_pW_T_R NO_pW_T_R CA_pW_T_R

cd "$mypath/raw_data/agriculture"

* area
preserve
clear
import excel using ///
"1.1_HSS-I.42.xlsx" , ///
cellrange(AC8:AD17) sheet("Worksheet")
rename AC area_hss
rename AD year

tempfile area1
save "`area1'"
restore

preserve
clear
import excel using ///
"1.2 - Landw_Strukturerhebung.xlsx" , ///
cellrange(A1:B29) sheet("stata") firstrow
tempfile area2
save "`area2'"
restore


* revenue
preserve
clear
import excel using ///
"2.1 - HSS-I.27a.xlsx" , ///
cellrange(T17:Y93) sheet("Worksheet") 
keep T U Y
rename Y year
rename T netrev_ha
rename U netrev_pct

tempfile rev1
save "`rev1'"
restore


preserve
clear
import excel using ///
"2.2 - HSS-I.27b.xlsx" , ///
cellrange(A17:G32) sheet("Worksheet") 
keep A F G
rename A year
rename F netrev_ha
rename G netrev_pct

append using "`rev1'"

tab year
tempfile rev2
save "`rev2'"
restore


* interest rate

preserve
use "3.1 - JSTdatasetR6.dta", clear
keep year country stir ltrate
keep if country == "Switzerland"
drop country
tempfile interst1
save "`interst1'"
restore

		/* Source:
		Òscar Jordà, Katharina Knoll, Dmitry Kuvshinov, Moritz Schularick, 
		and Alan M. Taylor. 2019. 
		"The Rate of Return on Everything, 1870–2015." 
		Quarterly Journal of Economics, 134(3), 1225-1298. 

		https://www.macrohistory.net/database/
		*/


preserve
clear
import excel using ///
"3.2 - HSS-I.32.xlsx" , ///
cellrange(AB53:AC81) sheet("Worksheet") 
rename AC year
rename AB debtrate

tempfile interst2
save "`interst2'"
restore

merge 1:1 year using "`area1'", nogen
merge 1:1 year using "`area2'", nogen
merge 1:1 year using "`rev2'", nogen
merge 1:1 year using "`interst1'", nogen
merge 1:1 year using "`interst2'", nogen

order year area* netrev* stir ltrate debtrate ch*
sort year
tsset year


			* * * * * * PLOT DATA AND TRANSFORM * * * * *
// plot raw data
tw 	(line stir year if year>1900) (line ltrate year if year>1900)				///
	(line debtrate year if year>1900, lw(*2)) ,									///
	yla(-2(1)10, grid) xla(1900(10)2020, grid) xtitle("")						///
	yline(0, lcolor(black))	ytitle("Interest rate (in %)")						///
	legend(order(1 "short-term" 2 "long-term" 3 "debt rate" ) row(1)) 			///
	name(raw_rates, replace)
 
mylabels 0(0.2)2.2, myscale(@*1000000) local(myla)
tw 	(line area_hss year if year>1900) (line area_serh year if year>1900),		///
	yla(`myla', grid) xla(1900(10)2020, grid) xtitle("") 						///
	ytitle("Agricultural land (in mio ha)")	yline(0, lcolor(black))				///
	legend(order(1 "HSS" 2 "Strukturerhebung") row(1)) 							///
	name(raw_area, replace)

tw 	(line netrev_ha year if year>1900),											///
	yla(-1000(250)1000, grid) xla(1900(10)2020, grid) yline(0, lcolor(black))	///
	xtitle("") 	ytitle("Net revenue per ha (in CHF)") legend(off) 				///
	name(raw_revenue, replace)

	
// moving averages (smoothed data)
foreach var in stir ltrate debtrate netrev_ha {
	tssmooth ma `var'_sm10 = `var' , window(5 1 5)
	tssmooth ma `var'_sm20 = `var' , window(10 1 10)
}


// plot smoothed data
tw 	(line stir_sm10 year if year>1900) (line ltrate_sm10 year if year>1900)		///
	(line debtrate_sm10 year if year>1900, lw(*2)) ,							///
	yla(-2(1)10, grid) xla(1900(10)2020, grid) xtitle("")						///
	yline(0, lcolor(black))	ytitle("Interest rate (in %)")						///
	legend(order(1 "short-term" 2 "long-term" 3 "debt rate" ) row(1)) 			///
	name(sm10_rates, replace)

tw 	(line netrev_ha_sm10 year if year>1900),									///
	yla(-1000(250)1000, grid) xla(1900(10)2020, grid) yline(0, lcolor(black))	///
	xtitle("") 	ytitle("Net revenue per ha (in CHF)") legend(off) 				///
	name(sm10_revenue, replace)


tw 	(line stir_sm20 year if year>1900) (line ltrate_sm20 year if year>1900)		///
	(line debtrate_sm20 year if year>1900, lw(*2)) ,							///
	yla(-2(1)10, grid) xla(1900(10)2020, grid) xtitle("")						///
	yline(0, lcolor(black))	ytitle("Interest rate (in %)")						///
	legend(order(1 "short-term" 2 "long-term" 3 "debt rate" ) row(1)) 			///
	name(sm20_rates, replace)

tw 	(line netrev_ha_sm20 year if year>1900),									///
	yla(-1000(250)1000, grid) xla(1900(10)2020, grid) yline(0, lcolor(black))	///
	xtitle("") 	ytitle("Net revenue per ha (in CHF)") legend(off) 				///
	name(sm20_revenue, replace)
	

// capitalize total reveneue to obtain total wealth value
ipolate area_hss year, gen(area_ipol) epolate
replace area_ipol =. if year > 1996

gen total_rev = area_ipol * netrev_ha_sm20 


gen W_a_cap_stir = total_rev/(stir_sm20/100)/1000000
gen W_a_cap_ltrate = total_rev/(ltrate_sm20/100)/1000000
gen W_a_cap_debtrate = total_rev/(debtrate_sm20/100)/1000000



tw 	(line W_a_cap_stir year if year>1900) 										///
	(line W_a_cap_ltrate year if year>1900)										///
	(line W_a_cap_debtrate year if year>1900, lw(*2)) ,							///
	yla(0(5000)30000, grid) xla(1900(10)2020, grid) xtitle("")					///
	yline(0, lcolor(black))	ytitle("Agricultural wealth (in mio CHF)")			///
	legend(order(1 "short-term" 2 "long-term" 3 "debt rate" ) row(1)) 			///
	name(agriwealth, replace)
	
	
	
gen WIR_a_ltrate = W_a_cap_ltrate/ch_nni_T*100
gen WIR_a_debtrate = W_a_cap_debtrate/ch_nni_T*100

tw 	(line WIR_a_ltrate year if year>1900)										///
	(line WIR_a_debtrate year if year>1900, lw(*2)) ,							///
	yla(0(25)400, grid) xla(1900(10)2020, grid) xtitle("")						///
	yline(0, lcolor(black))	ytitle("Agricultural wealth-income ratio (in %)")	///
	legend(order(1 "long-term" 2 "debt rate" ) row(1)) 							///
	name(WIR_agriwealth, replace)
	
	
gen ch_pWIR_w_agri = ch_pWIR*100 + WIR_a_ltrate
replace ch_pWIR_w_agri = ch_pWIR*100 if ch_pWIR_w_agri ==.

tw 	(line ch_pWIR_w_agri year if year>1900),									///
	yla(0(100)1000, grid) xla(1900(10)2020, grid) xtitle("")					///
	yline(0, lcolor(black))	ytitle("Total wealth-income ratio (in %)")			///
	legend(off) 																///
	name(WIR_total_new, replace)
	

replace  ch_pWIR = ch_pWIR*100
	
tw 	(line ch_pWIR_w_agri year if year>1900) (line  ch_pWIR year if year>1900),	///
	yla(0(100)1000, grid) xla(1900(10)2020, grid) xtitle("")					///
	yline(0, lcolor(black))	ytitle("Total wealth-income ratio (in %)")			///
	legend(order(1 "w/ agriculture" 2 "w/o agriculture"))						///
	name(WIR_total_new, replace)
	

gen share_w_agri = W_a_cap_ltrate/ch_pW_T*100

tw 	(line share_w_agri year if year>1949, lw(*2) lcol(navy)) 								///
	(pcarrowi 17.5 1980.5 17.5 1960, lcol(red) mcol(red) msize(*1.8))			///
	(pcarrowi 5.5 1994.5 1.7 1981.8, lcol(black) mcol(black) ),			///
	xla(1950(10)2020, grid) xmtick(1950(5)2020, grid) xtitle("")				///
	yla(0(2)20, grid) ymtick(0(1)20, grid) yline(0, lcolor(black))									///
	ytitle("Estimated share of agricultural wealth" "in total private wealth (in %)")	///
	xline(1981, lcolor(red)) 													///
	text(18 1980.5 "1981: year from which our" "backward extrapolation starts", 	///
	box lcolor(red) fcolor(white) just(left) margin(l+1 t+1 b+1) place(nw)) 	///
	text(6 1995 "Missing wealth from" "agriculture in 1981: 1.5%", 	///
	box lcolor(black) fcolor(white) just(left) margin(l+1 t+1 b+1) place(se)) 	///
	legend(off)																	///
	name(share_agriw, replace)
	

tw 	(line share_w_agri year if year>1900),  ///
	xla(1900(20)2020, grid) xmtick(1900(10)2020, grid) xtitle("")		///
	yla(0(10)60, grid) yline(0, lcolor(black))									///
	ytitle("Estimated share of agricultural wealth" "in total private wealth (in %)")		///
	legend(off)																	///
	name(share_agriw_19002020, replace)

* worth agricultural land and other domestic capital in terms of net private wealth
foreach country in AU DE FR ES IT GB SE US JP NO CA {
	gen `country'_phi_t = `country'_domW_agriW_T_R/`country'_pW_T_R*100
}



// safe figures
cd  "$mypath/output/figures/"

graph export "Fig_append_A_4.pdf", name(share_agriw) replace

	
	
